package zhjb.platform.web.module.system.service;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;

import zhjb.platform.util.MD5;
import zhjb.platform.web.module.system.bean.User;
import zhjb.platform.web.service.BaseService;

public class UserService extends BaseService {
	public User login(String userName, String pwd) {
		User user = null;
		try {
			List<User> users = dao.findAllByCriteria(DetachedCriteria.forClass(User.class).add(Restrictions.and(Restrictions.eq("username", userName), Restrictions.eq("userpwd", MD5.encoding(pwd)))));
			if (users != null && !users.isEmpty()) {
				user = users.get(0);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return user;
	}
	
	/**
	 * 找到所有的用户
	 * @return
	 */
	public List<User> findAllUser() {
		List<User> users = dao.findAllByCriteria(DetachedCriteria.forClass(User.class));
		return users;
	}

}
